<template>
	<view class="content">
		<view class="content-top">
			<view class='cell-group margin-cell-group'>
				<view class='cell-item'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>当前U</view>
					</view>
					<view class='cell-item-bd'>
						<text class="cell-bd-view">￥{{wallet.user_money}}</text>
					</view>
				</view>
				<view class='cell-item'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>提现U</view>
					</view>
					<view class='cell-item-bd'>
						<input class='cell-bd-input' placeholder='请输入要提现的U' v-model="money" focus type="digit"></input>
					</view>
				</view>
				<view class='cell-item'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>钱包地址</view>
					</view>
					<view class='cell-item-bd'>
						<input class='cell-bd-input' placeholder='请输入钱包地址' v-model="address" focus type="digit"></input>
					</view>
				</view>
				<view class='cell-item'>
					<view class='cell-item-hd'>
						<view class='cell-hd-title'>提现规则</view>
					</view>
					<view class='cell-item-bd'>
						<view class='cell-hd-title'>提现扣除2%手续费(U大于100可提现)</view>
						<!-- <input class='cell-bd-input' placeholder='请输入手机号' v-model="iPhone" focus type="digit"></input> -->
					</view>
				</view>
			</view>
		</view>
		<view class="button-bottom">
			<button class="btn btn-square btn-b" hover-class="btn-hover2" @click="navigateToHandle">去提现</button>
		</view>
		<u-keyboard ref="uKeyboard" mode="number" v-model="showkey" @change="valChange" @confirm="Handle"></u-keyboard>
	</view>
</template>

<script>
	import {
		getWallet,
		withdrawal
	} from '@/api/user';
	export default {
		data() {
			return {
				// user: {}, // 用户信息
				money: '', // 提现的金额
				wallet: {}, // 用户信息
				iPhone: "",
				address: "",
				showkey: false,
				value:''
			}
		},
		onLoad() {
			this.getWallets()
		},
		methods: {
			// 获取用户信息
			getWallets() {
				getWallet().then(res => {
					if (res.code == 1) {
						this.wallet = res.data
						console.log(this.wallet)
					}
				});
			},
			valChange(val) {
				// 将每次按键的值拼接到value变量中，注意+=写法
				this.value += val;
				console.log(this.value);
			},
			Handle(){
				let data={
					money:this.money,
					pay_password:this.value,
					pay_address:this.address
				}
				withdrawal(data).then(res => {
					this.value=''
					if (res.code == 1) {
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
						setTimeout(function() {
							uni.redirectTo({
								url: "../user_wallet/user_wallet"
							})
						}, 2000);
					}
				});
			},
			// 去充值
			navigateToHandle() {
				if (!Number(this.money)) {
					// this.$common.errorToShow('请输入要充值的金额')
					uni.showToast({
						title: '请输入要提现的金额',
						duration: 2000,
						icon: "none"
					});
				}else if(this.address=='') {
					uni.showToast({
						title: '请输入提现地址',
						duration: 2000,
						icon: "none"
					});
				}else {
					this.showkey = true
					
					
				}
			}
		}
	}
</script>

<style>
	.user-head {
		height: 100upx;
	}

	.user-head-img {
		height: 90upx;
		width: 90upx;
		border-radius: 50%;
	}

	.cell-hd-title {
		color: #333;
	}

	.cell-item-bd {
		color: #666;
		font-size: 26upx;
	}

	.button-bottom .btn {
		width: 100%;
	}
</style>
